# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_for_hbase_operator import SparkSqlOperator
from jms.dm.route.dm_route_selected import dm__dm_route_whole_selected
from jms.time_sensor.time_after_09_00 import time_after_09_00
hbase_dm_route_recommend_2hbase_new = SparkSqlOperator(
    task_id='hbase_dm_route_recommend_2hbase_new',
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    # execution_timeout=timedelta(minutes=30),
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='hbase_dm_route_recommend_2hbase_new_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/hbase/dm_route_recommend_2hbase_new/execute.sql',
    driver_memory='8G',
    driver_cores=1,
    executor_cores=4,
    executor_memory='8G',
    num_executors=30,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict',  # 动态分区

        'spark.hadoop.hive.exec.dynamic.partition': 'true',  # 动态分区开启
        'spark.sql.shuffle.partitions': 32,
        'spark.yarn.maxAppAttempts': 1,
        'spark.shuffle.file.buffer': '64K',
        'spark.reducer.maxSizeInFlight': '96M',

        'spark.hbase.table.partition': 1000,
        'spark.hive.hbasetable': 'dim_route_recommend',
        'spark.hive.hbase.max.hfiles': 1000,
        'spark.hive.hbase.rowkey.list': 'in_branch_id,main_id,out_branch_id,dt',
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    yarn_queue='pro',
)
hbase_dm_route_recommend_2hbase_new << [dm__dm_route_whole_selected,time_after_09_00]
